<template>
  <header class="header">
      <h1>todos</h1>
      <input class="new-todo" placeholder="请输入任务名称" @keyup.enter="add" v-model.trim="name" autofocus />
    </header>
</template>

<script>
export default {
  data() {
    return {
      name: ''
    }
  },
  methods: {
    add() {
      if(this.name === '') return
      // 子传父
      this.$emit('add', this.name)
      // 清空内容
      this.name = ''
    }
  }
}
</script>

<style>

</style>